<template>
	<view>
		<view class="item" :key="key" v-for="(sku,key) in orderInfo.skuList">
			<uni-list>
				<uni-list-item :thumb="sku.cover" :title="sku.title + '(' + sku.spec + ')'" show-arrow="false"></uni-list-item>
			</uni-list>
			<view class="rate">
				<xy-radio-group :list="radioData" v-model="commentList[key].rate"></xy-radio-group>
			</view>
			<view class="content">
				<textarea v-model="commentList[key].content" placeholder="请填写评价" />
			</view>
			<view class="images">
				<xy-upload-image
					:limit="upload.limit"
					:driver="upload.driver"
					:signUrl="upload.signUrl"
					:action="upload.action"
					:header="upload.header"
					v-model="commentList[key].images"
				></xy-upload-image>
			</view>
		</view>
		<button type="primary" class="sumbit" @click="submit">提交</button>
	</view>
</template>

<script>
	import {mapState, mapMutations} from 'vuex';
	export default {
		components: {
		},
		computed: {
			...mapState(['app', 'user'])
		},
		data() {
			return {
				upload: {
					driver: 'upload_oss',
					limit: 5,
					signUrl: this.util.baseUrl() + 'v1/upload_oss/index/sign',
					action: this.util.baseUrl() + 'v1/core/index/upload',
					header: {
						Authorization: this.util.getToken()
					}
				},
				radioData: [
					{value: '5', 'title': '好评'},
					{value: '3', 'title': '中评'},
					{value: '0', 'title': '差评'}
				],
				orderNo: '',
				orderInfo: {},
				commentList: {}
			}
		},
		onLoad(options){
			this.orderNo = options.orderNo;
			this.orderInfo = uni.getStorageSync('ishopCommmentCurrent');
			for (var i = 0; i < this.orderInfo.skuList.length; i++) {
				this.commentList[i] = {
					itemId: this.orderInfo.skuList[i].itemId,
					skuId: this.orderInfo.skuList[i].skuId,
					skuSpec: this.orderInfo.skuList[i].spec,
					rate: 0,
					content: '',
					images: []
				};
			}
			console.log(this.orderInfo);
			this.loadData();
		},
		methods: {
			radioChange(evt){
				console.log(evt);
				this.commentList[key].rate = evt.target.value;
			},
			async loadData(){
			},
			async submit(){
				console.log(this.commentList);
				let res = await this.util.request({
					url: '/v1/ishop/comment/add',
					method: 'POST',
					data: {
						orderNo: this.orderNo,
						commentList: this.commentList
					}
				});
				if (res.code == 200) {
					this.util.showToast({
						title: res.msg,
						icon: 'success',
						duration: 1000
					});
					uni.navigateBack();
				} else {
					this.util.showToast({
						title: res.msg,
						icon: 'loading',
						duration: 1500
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		background: #fff;
		padding-bottom: 10px;
		.rate {
			padding: 10px 15px;
		}
		.content {
			margin: 5px 15px;
			padding: 5px;
			border: 1px solid $border-color-base;
		}
		.images {
			padding: 5px 15px;
		}
	}
	.sumbit {
		margin: 30px 10px;
	}
</style>
